package bbs.mvc.Servlet;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "loginsServlet", value = "/loginspc-servlet")
public class LoginspecialServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        this.doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

        HttpSession session = request.getSession(true);

        String user =session.getAttribute("user").toString();

        response.setContentType("text/html;charset=utf-8");

        if(user.equals("admin")) {
            response.sendRedirect("./admin/admin.jsp");
           }
        else {
            PrintWriter out = response.getWriter();
            out.print("<script language='javascript'>alert('您不是管理员');window.location.href='welcome.jsp';</script>");
            response.sendRedirect("./admin/Arstartes.jsp");
        }
        }
}